part of marqueer;

class MarqueerController {
  MarqueerController();

  final _marquees = <MarqueerState>[];
  void _attach(MarqueerState marqueer) {
    _marquees.add(marqueer);
  }

  void _detach(MarqueerState marqueer) {
    _marquees.remove(marqueer);
  }

  bool get hasClients => _marquees.isNotEmpty;

  bool get isAnimating {
    assert(hasClients, "Not found any attached marqueer widget");
    assert(_marquees.length == 1, "Multiple marqueer widget attached.");
    return _marquees.single.animating;
  }

  void start() {
    if (!hasClients) return;
    for (var state in _marquees) {
      state.start();
    }
  }

  void stop() {
    if (!hasClients) return;
    for (var state in _marquees) {
      state.stop();
    }
  }

  void updatePPS(double pps) {
    if (!hasClients) return;
    for (var state in _marquees) {
      state.updatePPS(pps);
    }
  }

  Duration? getDuration(){
    assert(hasClients, "Not found any attached marqueer widget");
    if (_marquees != null && _marquees is List && _marquees.length > 0) {
      MarqueerState state = _marquees.first;
      return state.getDuration();
    }
    return null;
  }



  void interactionEnabled(bool enabled) {
    assert(hasClients, "Not found any attached marqueer widget");
    for (var state in _marquees) {
      state.interactionEnabled(enabled);
    }
  }
}
